import axios from 'axios'
import NProgress from 'nprogress'
import store from 'store'
const axiosIns = axios.create({
    baseURL: '/api',
    timeout: 7000
})
axiosIns.interceptors.request.use(config => {
    //请求前
    NProgress.start();
    //给请求头添加uuid
    config.headers.userTempId = store.state.user.uuid
    //为/api开头的所有请求都加上 token
    const token = localStorage.getItem('login_token')
    if(token)
        config.headers.token = token
    return config;
}, error => {
    return Promise.reject(error);
});

axiosIns.interceptors.response.use(response => {
    //请求成功
    NProgress.done();
    return response.data;
}, error => {
    //请求失败
    NProgress.done();
    return Promise.reject(error);
});
export default axiosIns